<?php
/**
 * 用户组控制器
 * UserModel: LLW
 * Date: 2020/1/08/0001
 * Time: 11:30
 */
namespace app\caidongweb\controller;
use app\caidongweb\model\AdminModel;
use app\caidongweb\model\AuthGroup as AuthGroupModel;
use app\caidongweb\model\Rule;
use think\Request;

/**
 * Class AuthGroup
 * 管理员组类
 * @package app\caidongweb\controller
 */
class AuthGroup extends BaseController
{
    protected $admin;
    protected $authGroup;
    protected $authRule;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->admin = new AdminModel();
        $this->authGroup = new AuthGroupModel();
        $this->Rule = new Rule();
    }

    //后台用户组列表
    public function index()
    {
        $list = $this->authGroup->index();
        $this->assign('list',$list);
        $this->assign('page',$list->render());
        $this->assign('times',time());
        return $this->fetch('auth/index');
    }
    //用户组权限编辑
    public function edit()
    {
        if(input('post.')){
            $res = $this->authGroup->edit();
            return $res;
        }else{
            $data = $this->authGroup->getInfo();
            $auth_rule = $this->Rule->getList();
            $this->assign('auth_rule',$auth_rule);
            $this->assign('data',$data);
            return $this->fetch('auth/edit');
        }
    }
    //添加用户组
    public function add()
    {
        if(input('post.')){
            $res = $this->authGroup->add();
            return $res;
        }else{
            $auth_rule = $this->Rule->getList();
            $this->assign('auth_rule',$auth_rule);
            return $this->fetch('auth/add');
        }
    }
    //获取信息
    public function getInfo(){
        $data = $this->authGroup->getInfo();
        return $data;
    }
    //批量删除
    public function delList()
    {
        $id = input('id');
        $res = $this->del('auth_group',['id'=>$id]);
        if($res){
            return $this->returnData(1,'删除成功');
        }else{
            return $this->returnData(-1,'失败');
        }
    }
    //编辑状态
    public function updateStatus()
    {
        $res = $this->authGroup->updateStatus();
        return $res;
    }
}